package com.yesep.learn.netty.tcp.protocol.session;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.netty.channel.ChannelHandlerContext;

/**
 * @Description: 
 */
public class SessionOnline {
	private static final Logger log = LoggerFactory.getLogger(SessionOnline.class);

	/**
	 * 在线站点缓存
	 */
	private static Map<String, String> onlineSessionMap = new HashMap<>();

	public static void online(ChannelHandlerContext ctx) {
//		Channel channel = ctx.channel();
//		SocketAddress remoteAddr = channel.remoteAddress();
//		logger.info("站点离线   ID={} remoteAddress=:{}", channel.id(), remoteAddr);
//		onlineSessionMap.remove(remoteAddr.toString());
	}

	public static void offline(String remoteAddr) {
		onlineSessionMap.remove(remoteAddr);
		System.out.println("--------------offline----------------");
	}

	/**
	 * 发送错误报文次数大于设定值，视为可疑的危险报文
	 * @param remoteAddr
	 * @return
	 */
	public static boolean danger(String remoteAddr) {
		return true;
	}

	/**
	 * 错误报文次数自动加1
	 * @param remoteAddr
	 */
	public static void errorCount(String remoteAddr) {

	}

	public static void getOnlineSession(String remoteAddr) {
		onlineSessionMap.get(remoteAddr);
	}
}
